{extend name="property/public/insidePageBase" /}
{block name="title"}添加物业{/block}
{block name="css"}
{__block__}
<style>
    .layui-btn {
        padding: 0 8px;
    }
</style>
{/block}
{block name="body"}
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form  layui-form-pane">
            <div class="layui-row">
                <div class="layui-col-xs5">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">物 业 简 称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="require" autocomplete="off" placeholder="请输入物业简称" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs7">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">物业缩略图</label>
                        <div class="layui-input-inline">
                            <input type="text" name="picture" placeholder="请上传物业图片" id="picture" class="layui-input">
                        </div>
                        <img class="checkPictureByImg picture" style="width: 40px;height: 40px;">
                        <div class="layui-input-inline layui-btn-container" style="width: auto;">
                            <button type="button" class="layui-btn layui-btn-primary uploadImg" lay-data="{field: 'picture',data:{dir:'property/picture', field:'picture'}}">
                                <i class="layui-icon">&#xe67c;</i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs4">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">物业管理员</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" lay-verify="require" autocomplete="off" placeholder="请输入物业管理员姓名" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs4">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">管理员电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="mobile" lay-verify="require" autocomplete="off" placeholder="请输入物业管理员电话" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">物 业 编 码</label>
                        <div class="layui-input-block">
                            <input type="text" name="code" value="{$code??''}" minlength="5" maxlength="5"  lay-verify="require" autocomplete="off" placeholder="请输入物业编码" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs5">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">物 业 类 型</label>
                        <div class="layui-input-block" id="property_cate_data_show"></div>
                    </div>
                </div>
                {if $addCateAuth}
                <div class="layui-col-xs1" >
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-fluid addPropertyCate"> 添加类型 </button>
                </div>
                {/if}
                <div class="layui-col-xs3" >
                    <div class="layui-input-group">
                        <div class="layui-input-split layui-input-prefix">占地面积</div>
                        <input type="text" name="cover_area"  placeholder="占地面积"  class="layui-input">
                        <div class="layui-input-split layui-input-suffix">㎡</div>
                    </div>
                </div>
                <div class="layui-col-xs3" >
                    <div class="layui-input-group">
                        <div class="layui-input-split layui-input-prefix">建筑面积</div>
                        <input type="text" name="building_area"  placeholder="建筑面积"  class="layui-input">
                        <div class="layui-input-split layui-input-suffix">㎡</div>
                    </div>
                </div>
            </div>



            <div class="layui-row">
                <div class="layui-col-xs5">
                    <div class="layui-form-item">
                        <label class="layui-form-label">物 业 归 属</label>
                        <div class="layui-input-block" id="firm_data_show"></div>
                    </div>
                </div>
                {if $addFirmAuth}
                <div class="layui-col-xs1" >
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-fluid addFirmInfo">添加公司</button>
                </div>
                {/if}
                <div class="layui-col-xs6" >
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">所 属 地 址</label>
                        <div class="layui-input-block">
                            <div class="layui-input-inline" style="width: 228px;">
                                <input type="text" name="address" id="address" placeholder="请输入所属地址" class="layui-input" autocomplete="off"/>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn" type="button" id="map_location"><i class="layui-icon layui-icon-location"></i>定位</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-xs4">
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">线上直付通</label>
                        <div class="layui-input-block">
                            <select name="pay_config[online_status]" id="online_status" lay-filter="online_status">
                            <option value="">--请选择--</option>
                            <option value="1">开启</option>
                            <option value="2">关闭</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="online-status" style="display: none">
                    <div class="layui-col-xs5">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">收款账户</label>
                            <div class="layui-input-block">
                                <select name="pay_config[adapay_user_id]">
                                    <option value="">请选择</option>
                                    {foreach $adapayUserList as $v}
                                    <option value="{$v['id']}">
                                        {if $v['customer_type'] == 1}【个人】{$v['user_name']}（{$v['remark']}）{/if}
                                        {if $v['customer_type'] == 2}【企业】{$v['name']}（{$v['remark']}）{/if}
                                    </option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs3">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">支付手续费</label>
                            <div class="layui-input-block">
                                <select name="pay_config[pay_service_fee]">
                                    <option value="">请选择</option>
                                    <option value="1"> 自行承担</option>
                                    <option value="2"> 住户承担</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item" pane="">
                <label class="layui-form-label">线下收款码</label>
                <div class="layui-input-block">
                    <input type="radio" name="pay_config[offline_status]" lay-filter="offline-status" autocomplete="off" value="1" title="开启【收款码】">
                    <input type="radio" name="pay_config[offline_status]" lay-filter="offline-status" autocomplete="off" value="2" title="关闭" checked>
                </div>
            </div>

            <div class="offline-status" style="display: none">
                <div class="layui-form-item">
                    <label class="layui-form-label required">微信收款码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pay_config[wechat_code]" value="" placeholder="请上传微信收款码" id="wechat_code" class="layui-input">
                    </div>
                    <img src="" class="checkPictureByImg wechat_code" style="width: 80px;height: 40px;">
                    <div class="layui-input-inline layui-btn-container" style="width: auto;">
                        <button type="button" class="layui-btn layui-btn-primary uploadImg" lay-data="{field: 'wechat_code',data:{dir:'property/payment', field:'wechat_code'}}">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">支付宝收款</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pay_config[alipay_code]" value="" placeholder="请上传支付宝收款码" id="alipay_code" class="layui-input">
                    </div>
                    <img src="" class="checkPictureByImg alipay_code" style="width: 80px;height: 40px;">
                    <div class="layui-input-inline layui-btn-container" style="width: auto;">
                        <button type="button" class="layui-btn layui-btn-primary uploadImg" lay-data="{field: 'alipay_code',data:{dir:'property/payment', field:'alipay_code'}}">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">银行收款码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pay_config[bank_code]" value="" placeholder="请上传银行收款码" id="bank_code" class="layui-input">
                    </div>
                    <img src="" class="checkPictureByImg bank_code" style="width: 80px;height: 40px;">
                    <div class="layui-input-inline layui-btn-container" style="width: auto;">
                        <button type="button" class="layui-btn layui-btn-primary uploadImg" lay-data="{field: 'bank_code',data:{dir:'property/payment', field:'bank_code'}}">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-form-item" pane="">
                <label class="layui-form-label">线 下 转 账</label>
                <div class="layui-input-block">
                    <input type="radio" name="pay_config[for_the_public]" lay-filter="for-the-public" autocomplete="off" value="1" title="开启【通过账号转账】">
                    <input type="radio" name="pay_config[for_the_public]" lay-filter="for-the-public" autocomplete="off" value="2" title="关闭" checked>
                </div>
            </div>

            <div class="layui-row for_the_public"  style="display: none">
                <div class="layui-row">
                    <div class="layui-col-xs3">
                        <div class="layui-form-item">
                            <label class="layui-form-label">开户银行</label>
                            <div class="layui-input-block">
                                <input type="text" name="pay_config[bank_name]"  autocomplete="off" placeholder="请输入开户银行" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs5">
                        <div class="layui-form-item">
                            <label class="layui-form-label">开户人姓名</label>
                            <div class="layui-input-block">
                                <input type="text" name="pay_config[bank_username]"  autocomplete="off" placeholder="请输入开户人姓名" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs4">
                        <div class="layui-form-item">
                            <label class="layui-form-label">银行账号</label>
                            <div class="layui-input-block">
                                <input type="text" name="pay_config[bank_account]"  autocomplete="off" placeholder="请输入银行开户账号" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">账单温馨提示</label>
                <div class="layui-input-block">
                    <textarea name="pay_config[bill_prompt]"  placeholder="请输入账单温馨提示" class="layui-textarea"></textarea>
                </div>
            </div>

			<div class="layui-form-item layui-form-text">
			    <label class="layui-form-label">物业备注说明</label>
			    <div class="layui-input-block">
			      <textarea name="remark"  placeholder="请输入备注说明" class="layui-textarea"></textarea>
			    </div>
			</div>
            <div class="layui-form-item layui-hide">
                <input type="hidden" name="longitude" id="longitude" />
                <input type="hidden" name="latitude" id="latitude" />
                <button class="layui-btn" lay-submit lay-filter="submitBtn" id="submitBtn">提交</button>
            </div>
        </div>
    </div>
</div>
<script id="property_cate_data_tpl" type="text/html">
    <input type="text" name="cate_id" id="property-cate-name" autocomplete="off" class="layui-input">
</script>
<script id="firm_data_tpl" type="text/html">
    <input type="text" name="firm_id" id="firm-name" autocomplete="off" class="layui-input">
</script>
{/block} {block name="js"} {__block__}
<script>
    layui.use(['form', 'layer', 'layCascader', 'laytpl'], function() {
        var form = layui.form,layer = layui.layer,  $ = layui.$,layCascader = layui.layCascader, laytpl = layui.laytpl;
        $('.uploadImg').selectImages({
            confirm:function(res,elem,data) {
                $('#' + data.field).val(res[0].src);
                $('.' + data.field).attr('src',res[0].src)
            }
        });
        $('#map_location').on('click', function() {
            parent.layer.open({
                type: 2,
                title: '定位',
                content: "/static/maplocation/index.html",
                area: ['80%', '80%'],
                btn: ['确认','取消'],
                yes: function(index, layero){
                    choseeArea = parent.window.frames['layui-layer-iframe'+index].choseeArea;
                    if(choseeArea === undefined) {
                        return parent.layer.msg('请选择地区');
                    }
                    $('#address').val(choseeArea.regeocode.formattedAddress);
                    $('#latitude').val(choseeArea.lnglat.lat);
                    $('#longitude').val(choseeArea.lnglat.lng);
                    parent.layer.close(index);
                }
            });
        });

        function loadPropertyCateData() {
            $.get("{:request()->url()}", {get_type: 'getPropertyCateData'}, function(res) {
                if(res.code !== 0) {
                    return layer.msg(res.msg)
                }
                var getTpl = document.getElementById('property_cate_data_tpl').innerHTML; // 获取模板字符
                var elemView = document.getElementById('property_cate_data_show'); // 视图对象
                // 渲染并输出结果
                laytpl(getTpl).render({}, function(str){
                    elemView.innerHTML = str;
                    layCascader({
                        elem: '#property-cate-name',
                        clearable: true,
                        value: 0,
                        options: res.data
                    });
                });
            })
        }
        loadPropertyCateData()

        $('.addPropertyCate').on('click', function() {
            var url = '{:url("propertyCateAdd")}';
            var index = parent.layer.open({title: '添加',type: 2,shade: 0.2, maxmin:true,area: ['600px', '400px'], content: url, btnAlign: 'c' , btn: ['确定', '取消'] , yes: function (index, layero) {
                    var iframeWindow = parent.window['layui-layer-iframe' + index] , submit = layero.find('iframe').contents().find("#submitBtn");
                    iframeWindow.layui.form.on('submit(submitBtn)', function (data) {
                        var field = data.field; //获取提交的字段
                        var loadAdd = parent.layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                        $.post(url, field, function (res) {
                            parent.layer.close(loadAdd);
                            if (res.code === 0) {
                                loadPropertyCateData()
                                parent.layer.close(index); //关闭弹层
                                parent.layer.msg(res.msg, {icon: 6, offset: '15px'});
                            } else {
                                parent.layer.msg(res.msg, {icon: 5, offset: '15px'});
                            }
                        });
                    });
                    submit.trigger('click');
                }
            });
        });

        form.on('select(online_status)', function(data) {
            if(data.value == 1) {
                $('.online-status').show();
            } else {
                $('.online-status').hide();
            }
        });
        form.on('radio(offline-status)', function(data) {
            if(data.value == 1) {
                $('.offline-status').show();
            } else {
                $('.offline-status').hide();
            }
        });
        form.on('radio(for-the-public)', function(data) {
            if(data.value == 1) {
                $('.for_the_public').show();
            } else {
                $('.for_the_public').hide();
            }
        });
    });
</script>
{/block}